cmake_minimum_required(VERSION 3.8)
project(move_to_gps_target_c)

# 设置编译选项
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 添加依赖查找路径
list(APPEND CMAKE_MODULE_PATH "/usr/share/cmake/geographiclib")



include_directories(
    $ENV{ASTRA_SDK_INCLUDE}
)

link_directories($ENV{ASTRA_SDK_LIB})



# 查找必备依赖
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(rclcpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2 REQUIRED)
find_package(rosgraph_msgs REQUIRED)
find_package(GeographicLib REQUIRED)  # 确保已安装libgeographic-dev
find_package(nav2_msgs REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(image_transport REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(OpenCV REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(apriltag REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)  # 新增这个查找包
find_package(PkgConfig REQUIRED)
find_package(nlohmann_json REQUIRED) 
pkg_check_modules(LIBAV REQUIRED libavcodec libavformat)

# 定义所有可执行文件
add_executable(apm_gps_tf_node src/apm_gps_tf_node.cpp)
add_executable(apm_gps_tf_node_real_fly src/apm_gps_tf_node_real_fly.cpp)
add_executable(multi_static_tf_broadcaster src/multi_static_tf_broadcaster.cpp)
add_executable(move_to_gps_target src/move_to_gps_target.cpp)
add_executable(apriltag_tf_publisher_node src/apriltag_tf_publisher_node.cpp)
add_executable(move_to_gps_target_real_fly src/move_to_gps_target_real_fly.cpp)
add_executable(apriltag_tf_publisher_node_real_fly src/apriltag_tf_publisher_node_real_fly.cpp)
add_executable(astra_node src/astra_node.cpp)

# 设置包含目录
target_include_directories(apm_gps_tf_node PRIVATE
  ${Eigen3_INCLUDE_DIRS}
  ${GeographicLib_INCLUDE_DIRS}
)

target_include_directories(apm_gps_tf_node_real_fly PRIVATE
  ${Eigen3_INCLUDE_DIRS}
  ${GeographicLib_INCLUDE_DIRS}
)

target_include_directories(apriltag_tf_publisher_node PRIVATE
  ${apriltag_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${Eigen3_INCLUDE_DIRS}
)

target_include_directories(apriltag_tf_publisher_node_real_fly PRIVATE
  ${apriltag_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${Eigen3_INCLUDE_DIRS}
)

target_include_directories(astra_node PRIVATE
  ${MPP_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)


# 设置依赖关系
ament_target_dependencies(apm_gps_tf_node
  rclcpp
  geometry_msgs
  std_msgs
  sensor_msgs
  tf2_ros
  tf2
  rosgraph_msgs
  ament_index_cpp
)

ament_target_dependencies(apm_gps_tf_node_real_fly
  rclcpp
  geometry_msgs
  std_msgs
  sensor_msgs
  tf2_ros
  tf2
  rosgraph_msgs
  ament_index_cpp
)


ament_target_dependencies(multi_static_tf_broadcaster
  rclcpp
  geometry_msgs
  tf2
  tf2_ros
)

ament_target_dependencies(move_to_gps_target
  rclcpp
  std_msgs
  geometry_msgs
  sensor_msgs
  nav2_msgs
  rclcpp_action
  tf2_ros
  ament_index_cpp
  tf2_geometry_msgs 
)

ament_target_dependencies(move_to_gps_target_real_fly
  rclcpp
  std_msgs
  geometry_msgs
  sensor_msgs
  nav2_msgs
  rclcpp_action
  tf2_ros
  ament_index_cpp
  tf2_geometry_msgs 
)

ament_target_dependencies(apriltag_tf_publisher_node
  rclcpp
  image_transport
  cv_bridge
  tf2
  tf2_ros
  geometry_msgs
  sensor_msgs
  ament_index_cpp
  rosgraph_msgs
  tf2_geometry_msgs 
)

ament_target_dependencies(apriltag_tf_publisher_node_real_fly
  rclcpp
  image_transport
  cv_bridge
  tf2
  tf2_ros
  geometry_msgs
  sensor_msgs
  ament_index_cpp
  rosgraph_msgs
  tf2_geometry_msgs 
)

ament_target_dependencies(astra_node
  rclcpp
  image_transport
  cv_bridge
  tf2
  tf2_ros
  std_msgs
  geometry_msgs
  sensor_msgs
  ament_index_cpp
  rosgraph_msgs
  tf2_geometry_msgs 
)

# 链接库
target_link_libraries(move_to_gps_target
  ${GeographicLib_LIBRARIES}  # 使用变量替代目标名
)

target_link_libraries(move_to_gps_target_real_fly
  ${GeographicLib_LIBRARIES}  # 使用变量替代目标名
)


target_link_libraries(apm_gps_tf_node
  ${GeographicLib_LIBRARIES}  # 使用变量替代目标名
  Eigen3::Eigen               # 使用现代CMake目标
  nlohmann_json::nlohmann_json
)

target_link_libraries(apm_gps_tf_node_real_fly
  ${GeographicLib_LIBRARIES}  # 使用变量替代目标名
  Eigen3::Eigen               # 使用现代CMake目标
  nlohmann_json::nlohmann_json
)

target_link_libraries(apriltag_tf_publisher_node
  apriltag::apriltag  # 使用现代CMake目标名称
  ${OpenCV_LIBS}
  yaml-cpp
  Eigen3::Eigen
)

target_link_libraries(apriltag_tf_publisher_node_real_fly
  apriltag::apriltag  # 使用现代CMake目标名称
  ${OpenCV_LIBS}
  yaml-cpp
  Eigen3::Eigen
)

target_link_libraries(astra_node
    astra
    astra_core
    $ENV{ASTRA_SDK_LIB}
    ${OpenCV_LIBS}  
    ${MPP_LIBRARIES}
    rockchip_mpp
    rockchip_vpu
    ${LIBAV_LIBRARIES}
)

# 安装配置
install(TARGETS
  apm_gps_tf_node
  apm_gps_tf_node_real_fly
  multi_static_tf_broadcaster
  move_to_gps_target
  move_to_gps_target_real_fly
  apriltag_tf_publisher_node
  apriltag_tf_publisher_node_real_fly
  astra_node
  DESTINATION lib/${PROJECT_NAME}
)

install(
  DIRECTORY config/
  DESTINATION share/${PROJECT_NAME}/config
)

ament_package()
